package bar.dark.lee.setting.sms.smsinsert;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import bar.dark.lee.BDConstents;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.setting.sms.InputData;

public class SmsInMoney 
{
	private int smsType; 
//	private boolean flagATM = false;
//	private boolean flagHalbu = false;
//	private String halbuMonth = "0";
//	
//	private boolean FLAG = true;
	private boolean available = false;
//	
//	private boolean outmoneyFlag = false;
//	
//	//1:check 2:credit
	private int checkcreditFlag = 0;
//	
	private final int CHECK = 1;
	private final int CREDIT = 2;
//	
	private String message;
	private InputData data;
//	
	private String date;
	
	public SmsInMoney(){};
	
	public SmsInMoney(InputData data, String message, String date, int smsType, int checkcreditFlag)
	{
		this.data = data;
		this.message = message;
		this.date = date;
		this.smsType = smsType;
		this.checkcreditFlag = checkcreditFlag;
		
		inMoney();
	}
	
	public boolean getAvailable()
	{
		return available;
	}
	
	public InputData getData()
	{
		return data;
	}
	
	public int getSmsType()
	{
		return smsType;
	}
	
	//TODO
	private void inMoney()
	{
		if ( data.getName().equalsIgnoreCase("KB인터넷뱅킹") )
		{
			/*
			 [KB인터넷뱅킹] 01/25 11:21 068210***0    입금 2,300,000원
			 */
			Pattern pName = Pattern.compile("(\\d{3,}\\*{1,6}\\d{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)\\s+잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pMoney2 = Pattern.compile("입금\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney2 = pMoney2.matcher(message);
			Pattern pMoney5 = Pattern.compile("입출금이\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney5 = pMoney5.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
//				Pattern pMemo = Pattern.compile("([^\\s]{2,})\\W*체\\s*크\\s*카\\s*드\\s*출\\s*금\\s*");	// 체크카드 출금 뒤
			//Pattern pMemo = Pattern.compile("\\*\\d+\\s+(.+)\\s+.+\\s+\\d*,*\\d*,*\\d*,*\\d\\s+잔액");
//				Pattern pMemo = Pattern.compile("\\*\\d+\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d\\s+잔액");
//				Matcher mMemo = pMemo.matcher(message);
//				Pattern pMemo2 = Pattern.compile("\\*\\d+\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d");
//				Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("KB인터넷뱅킹" + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney2.find()) 
			{
				for (int i=0; i<mMoney2.groupCount(); i++) 
				{
					data.setMoney((mMoney2.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney5.find()) 
			{
				for (int i=0; i<mMoney5.groupCount(); i++) 
				{
					data.setMoney((mMoney5.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
				//originalParsing();
			}
			
//				if (mMemo.find()) 
//				{
//					for (int i=0; i<mMemo.groupCount(); i++) 
//					{
//						data.setMemo1((mMemo.group(1)));
//						data.setMemo2((mMemo.group(1)));
//						data.setMemo3((mMemo.group(1)));
//						data.setMemo4((mMemo.group(1)));
//					}
//				}
//				else if (mMemo2.find()) 
//				{
//					for (int i=0; i<mMemo2.groupCount(); i++) 
//					{
//						data.setMemo1((mMemo2.group(1)));
//						data.setMemo2((mMemo2.group(1)));
//						data.setMemo3((mMemo2.group(1)));
//						data.setMemo4((mMemo2.group(1)));
//					}
//				}
//				else
//				{
//					available = false;
//					return;
//				}
			
			data.setMemo1("KB인터넷뱅킹 입금");
			data.setMemo2("KB인터넷뱅킹 입금");
			data.setMemo3("KB인터넷뱅킹 입금");
			data.setMemo4("KB인터넷뱅킹 입금");
			
			available = true;
		}
		else if (data.getName().indexOf("KB") != -1)
		{
			/*
			 * KB07/02 18:45 992010**621 ATM입금 30,000 잔액 200,000
			 * 
			 * [KB]08/17 15:43
				910452**381
				김재중
				스마트폰입금
				1,000,000
				
				[KB]09/17 12:38
				623102**030
				이효준
				전자금융입금
				123,123
				잔액456,456
				
				[KB]01/14 18:11
				910755**019
				체크카드할인
				카드입금(   
				2,500
				잔액90,538
				
				[KB]01/23 17:51
				381802**576
				체크카드할인
				카드입금(
				570
			 */
			Pattern pName = Pattern.compile("(\\d{3,}\\*{1,6}\\d{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("\\s+(\\d*,*\\d*,*\\d*,*\\d)\\s+잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pMoney2 = Pattern.compile("입금\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney2 = pMoney2.matcher(message);
			Pattern pMoney3 = Pattern.compile("카드입금\\(\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney3 = pMoney3.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
//				Pattern pMemo = Pattern.compile("([^\\s]{2,})\\W*체\\s*크\\s*카\\s*드\\s*출\\s*금\\s*");	// 체크카드 출금 뒤
			Pattern pMemo = Pattern.compile("\\*\\d+\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			//Pattern pMemo2 = Pattern.compile("\\*\\d+\\s+[^\\W]+\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d");
			Pattern pMemo2 = Pattern.compile("\\*\\d+\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("KB" + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney2.find()) 
			{
				for (int i=0; i<mMoney2.groupCount(); i++) 
				{
					data.setMoney((mMoney2.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney3.find()) 
			{
				for (int i=0; i<mMoney3.groupCount(); i++) 
				{
					data.setMoney((mMoney3.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1).replaceAll("\\s", " ")));
					data.setMemo2((mMemo.group(1).replaceAll("\\s", " ")));
					data.setMemo3((mMemo.group(1).replaceAll("\\s", " ")));
					data.setMemo4((mMemo.group(1).replaceAll("\\s", " ")));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1).replaceAll("\\s", " ")));
					data.setMemo2((mMemo2.group(1).replaceAll("\\s", " ")));
					data.setMemo3((mMemo2.group(1).replaceAll("\\s", " ")));
					data.setMemo4((mMemo2.group(1).replaceAll("\\s", " ")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("신한은행") != -1) )
		{
			/*
			 * 
			 * [신한은행]
				09월05일21시45분
				[110-***-122714]
				입급 30,000원
				(정혜진)
			 */
			
			Pattern pName = Pattern.compile("(\\d{2,}-.{2,}-\\d{2,}\\])");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("\\s+(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}월\\d{1,2}일)");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("신한은행" + "(" + (mName.group(1)).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
//				data.setMemo1("현금 입금");
//				data.setMemo2("현금 입금");
//				data.setMemo3("현금 입금");
//				data.setMemo4("현금 입금");
//				
//				smsType = BDConstents.IN_ATM_SMS;
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("신한i")) )
		{
			/*
			 * [신한i]056 111 ***09    01032459872k   입금 29954원  최종 0원
			 */
			
			Pattern pName = Pattern.compile("(\\d{2,}\\s+\\d{2,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금\\s+(\\d{1,})원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\*\\d{1,}\\s+(.+\\s*.+)\\s+입금");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("신한i" + "(" + mName.group(1).replaceAll("\\s", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if (data.getName().indexOf("신한") != -1)
		{
			
			/*
			 * 신한07/30 12:32 110-285-903850 입금 8,000 잔액 40,893
			 * 
			 * 
			 */
			Pattern pName = Pattern.compile("\\d{2}:\\d{2}\\s+(.+)\\s+입금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금\\s+(\\d*,*\\d*,*\\d*,*\\d)\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s+-*\\d*,*\\d*,*\\d*,*\\d\\s+(.+)");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("입금\\s+\\d*,*\\d*,*\\d*,*\\d\\s+(.+)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("신한" + "(" + (mName.group(1).replaceAll("-", "")) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					String memo = "내용 없음";
					if ( ! (mMemo2.group(1) != null) && (mMemo2.group(1).indexOf("잔액") == -1) )
					{
						memo = mMemo2.group(1);
					}
					data.setMemo1(memo);
					data.setMemo2(memo);
					data.setMemo3(memo);
					data.setMemo4(memo);
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("새마을금고") ) )
		{
			/*
			 * <새마을금고>382710**2 111우07 출금10,000 잔액100,000 07/25 19:54
			 * <새마을금고>900214**5[sms알림]출금170,400잔액4,150 8/5 21:24
			 * 
			 * <새마을금고>382710**2 홍길동 입금10,000 잔액30,000 07/20 03:17 
			 * <새마을금고>900214**3 노유환（메이드미 입금450,000 잔액1,015,575 08/07 18:07 
			 */
			
			Pattern pName = Pattern.compile("<새마을금고>(.{10})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금(\\d*,*\\d*,*\\d*,*\\d)\\s*잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\*\\d\\s*(.+)\\s*입금");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("새마을금고" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("SC은행") != -1))
		{
			/*
			 * SC은행210214**13 리틀브라운 4,000입금 잔액916,823 0805 11:19
			   SC은행606204**33 파리바게뜨구리 23,000입금 잔액29,638 0802 22:26
			   
			   SC은행272200**48
				동양　정선애
				4,800,000입금
				잔액100,045,027
				0830 21:07
				
				--------------------------
				
				SC은행272200**48
				（주）비비디오
				56,000,000입금
				잔액56,399,248
				0727 11:02
			 */
			Pattern pName = Pattern.compile("SC은행(.{10})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)입금\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{4})\\s*\\d{2}:\\d{2}");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d\\s+(.+\\s?.+)\\s+\\d*,*\\d*,*\\d*,*\\d입금\\s+");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("SC은행" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if (data.getName().equalsIgnoreCase("KEB"))
		{
			Pattern pName = Pattern.compile("(\\d{3,}-\\d{2,})\\*\\*\\d{2,}");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금:\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)).replace("-", "") +")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("부산") != -1) )
		{
			/*
			 * 부산08/15 10:22 273-12-0***03-0 세븐일레븐부산반여 (부산) 입금263,000 잔액264,465
			 * 부산07/15 14:09 112-2029-***0-01 (0358)카드 (부산) 입금60,000 잔액60,000
			 */
			Pattern pName = Pattern.compile("\\d{2}:\\d{2}\\s+(.+)\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("-.{1,3}\\s+(.+)\\s+입금");	// ???원 뒤에
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("부산" + "(" + ((mName.group(1)).replace("-", "")).substring(0, 10) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("하나은행")) || (data.getName().equalsIgnoreCase("하나")) )
		{
			/*
			 * 하나,08/13,11:10
				246******98407
				입금120,000원
				김건중
				잔액189,137원
				
				하나,09/19,17:29
				701******20505
				입금10,000원
				ＡＴＭ 
				잔액118,968원
				
				하나,04/24,09:02 
				641******00207 
				입금149,300원 
				잔액150,003원
				
				하나,08/12,14:19 
				608******48707 
				입금300,000원 
				최옥자

			 */
			Pattern pName = Pattern.compile("\\d{2}:\\d{2}\\s+(.+)\\s+입금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("입금\\d*,*\\d*,*\\d*,*\\d원\\s+(.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("입금\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("하나" + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					Pattern pMemo3 = Pattern.compile("ＡＴＭ");
					Matcher mMemo3 = pMemo3.matcher(mMemo.group(1));
					
					if (mMemo3.find())
					{
						data.setMemo1("현금 입금");
						data.setMemo2("현금 입금");
						data.setMemo3("현금 입금");
						data.setMemo4("현금 입금");
						
						smsType = BDConstents.IN_ATM_SMS;
					}
					else
					{
						data.setMemo1((mMemo.group(1)));
						data.setMemo2((mMemo.group(1)));
						data.setMemo3((mMemo.group(1)));
						data.setMemo4((mMemo.group(1)));
					}
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1(mMemo2.group(1));
					data.setMemo2(mMemo2.group(1));
					data.setMemo3(mMemo2.group(1));
					data.setMemo4(mMemo2.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( data.getName().indexOf("우리투자") > -1 )
		{
			/*
			 * [우리투자]김상혁님 200-01-64** 출금 04/13 [16:31] 50,000원 하나은행 정유래
			 */
			Pattern pName = Pattern.compile("님\\s*(.{1,6}-.{1,6}-.{1,6})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("님\\s*(.{1,9}\\*{1,9}.{1,9})\\s+입금");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("\\d{1,2}\\]\\s+(\\d*,*\\d*,*\\d*,*\\d)원\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}\\]\\s+\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("우리투자" + "(" + mName.group(1).replaceAll("-", "") + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("우리투자" + "(" + mName2.group(1).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("우리") != -1) )
		{
			/*
			 * 
			 * 우리 06/14 13:25
				*00605 
				지급 9,000원
				윤가네
				잔액 164,566원
			 */
			Pattern pName = Pattern.compile("(\\*\\d{3,})");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("(\\d{2,}\\*\\d{2,})");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("우리" + "(" + (mName.group(1)) + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("우리" + "(" + (mName2.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					Pattern pMemo3 = Pattern.compile("#\\d{4,}");
					Matcher mMemo3 = pMemo3.matcher(mMemo.group(1));
					
					if (mMemo3.find())
					{
						data.setMemo1("현금 입금");
						data.setMemo2("현금 입금");
						data.setMemo3("현금 입금");
						data.setMemo4("현금 입금");
						
						smsType = BDConstents.IN_ATM_SMS;
					}
					else
					{
						data.setMemo1((mMemo.group(1)));
						data.setMemo2((mMemo.group(1)));
						data.setMemo3((mMemo.group(1)));
						data.setMemo4((mMemo.group(1)));
					}
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("올레BeF") ) )
		{
			/*
			 * [올레BeF.충전] 20,000원 계좌충전, 박형민님 잔액:20,000원 06/20 18:32
			 */
//				Pattern pName = Pattern.compile("우리(.+)\\s+입금");
//				Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("\\s+(\\d*,*\\d*,*\\d*,*\\d)원\\s+계좌충전");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
//				Pattern pMemo = Pattern.compile(":\\d{2}\\]\\s+\\d*,*\\d*,*\\d*,*\\d원\\s+(.+)\\s+잔액");
//				Matcher mMemo = pMemo.matcher(message);
			
//				if (mName.find())
//				{
//					for (int i=0; i<mName.groupCount(); i++) 
//					{
					data.setName("올레BeF");
//					}
//				}
//				else
//				{
//					originalParsing();
//				}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//				if (mMemo.find()) 
//				{
//					for (int i=0; i<mMemo.groupCount(); i++) 
//					{
					data.setMemo1("계좌충전");
					data.setMemo2("계좌충전");
					data.setMemo3("계좌충전");
					data.setMemo4("계좌충전");
//					}
//				}
//				else
//				{
//					originalParsing();
//				}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("전북") ) )
		{
			/*
			 * [전북]####139
				입금500
				잔액147,123
				08/29 10:51
				SMS수수료(출금)
			 */
			
			Pattern pName = Pattern.compile("\\[전북\\](.+)\\s+입금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금(\\d*,*\\d*,*\\d*,*\\d)\\s+잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("전북" + "(" + mName.group(1).replaceAll("#", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("Citi") ) )
		{
			/*
			 * Citi 08/21 18:02 350-10***-262-01 입금 19,855 잔액 369,701 ＳＫ브로드밴드
			 */
			
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+)\\s+입금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금\\s+(\\d*,*\\d*,*\\d*,*\\d)\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s+-*\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("입금\\s+\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("Citi" + "(" + mName.group(1).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		
		if (data.getName() == null || data.getName().equalsIgnoreCase(""))
		{
			SmsInMoney2 sim2 = new SmsInMoney2(data, message, date, smsType, checkcreditFlag);
			this.data = sim2.getData();
			this.smsType = sim2.getSmsType();
			this.available = sim2.getAvailable();
		}
		if (data.getDate() == null || data.getDate().equalsIgnoreCase(""))
		{
			SmsInMoney2 sim2 = new SmsInMoney2(data, message, date, smsType, checkcreditFlag);
			this.data = sim2.getData();
			this.smsType = sim2.getSmsType();
			this.available = sim2.getAvailable();
		}
		if (data.getMoney() == null || data.getMoney().equalsIgnoreCase(""))
		{
			SmsInMoney2 sim2 = new SmsInMoney2(data, message, date, smsType, checkcreditFlag);
			this.data = sim2.getData();
			this.smsType = sim2.getSmsType();
			this.available = sim2.getAvailable();
		}
		if ( (data.getMemo1() == null) || (data.getMemo1().equalsIgnoreCase("")) 
				&& ( (data.getMemo2() == null) || (data.getMemo2().equalsIgnoreCase("")) )
				&& ( (data.getMemo3() == null) || (data.getMemo3().equalsIgnoreCase("")) )
				&& ( (data.getMemo4() == null) || (data.getMemo4().equalsIgnoreCase("")) ) )
		{
			SmsInMoney2 sim2 = new SmsInMoney2(data, message, date, smsType, checkcreditFlag);
			this.data = sim2.getData();
			this.smsType = sim2.getSmsType();
			this.available = sim2.getAvailable();
		}
		if (data.getName() == null || data.getName().equalsIgnoreCase("") 
				|| data.getDate() == null || data.getDate().equalsIgnoreCase("") 
				|| data.getMoney() == null || data.getMoney().equalsIgnoreCase("")
				|| ( data.getMemo1() == null || data.getMemo1().equalsIgnoreCase("") 
				&& data.getMemo2() == null || data.getMemo2().equalsIgnoreCase("")
				&& data.getMemo3() == null || data.getMemo3().equalsIgnoreCase("")
				&& data.getMemo4() == null || data.getMemo4().equalsIgnoreCase("") ) )
		{
			this.available = false;
			return;
		}
	}
		


}
